<template>
  <div class="w-[100%] h-[100%]">

    <div>
      <ContentWrap>
        <SearchBox :queryForm="searchList" :showExpland="false" @query="handleSearchQuery" :show-export="false"/>
      </ContentWrap>
    </div>

    <div class="mt-[30px]">
      <QueryTable
        :list="dataList"
        :total="total"
        :btns="tableBtnList"
        @execute="handleBtnClick"
        v-model="queryParams"
        :thead="th"
        :show-action="false"
        :show-section="false"
      >
        <template #tradeType="{row}">
        <div>
          {{ tradeType.find(at=>{return row.tradeType == at.value })?.label }}
        </div></template>

        <template #changeAmount="{row}">
            <div>{{ Math.round(row.changeAmount)/100 }}</div>
        </template>

        <template #originalAmount="{row}">
          <div>{{ Math.round(row.originalAmount)/100 }}</div>
        </template>

      </QueryTable>

    </div>
  </div>
</template>
<script setup lang="ts">
import Icon from "@/components/Icon/src/Icon.vue"
import QueryTable from "@/components/TableData/index.vue"
import ImagePreview from "@/components/ImagePreview/index.vue"
import type {TradeOrderQueryVO} from "@/api/mall/trade/order";
import {DICT_TYPE, getIntDictOptions, getStrDictOptions} from "@/utils/dict";
import type {PurchaseAdvice} from "@/api/purchase/advice/type";
import {throttle, confirmPromote} from "@/utils";
import {FeeApi} from "@/api/fee";

console.log(getStrDictOptions(DICT_TYPE.TRADE_ORDER_TYPE),"getStrDictOptions(DICT_TYPE.TRADE_ORDER_TYPE)")

const tradeType =  getStrDictOptions(DICT_TYPE.TRADE_TYPE)

const searchList: TradeOrderQueryVO[] = [
  {
    label: '交易类型',
    code: 'tradeType',
    type: 'select',
    options: tradeType
  },
  {
    label: '操作日期',
    code: 'createTime',
    type: 'dateRange'
  },
]
const initQueryParams = {
  pageNo: 1, pageSize: 10
}

const tableBtnList = ref([
  {
    color: '#3721FF',
    code: 'edit',
    name: '编辑'
  },
  {
    color: '#FF4E00',
    code: 'delItem',
    name: '删除'
  }
]);


const th = ref([
  {
    name: '交易类型',
    code: 'tradeType',
    type: 'numberRanger',
    search: true
  },
  {
    name: '交易备注',
    code: 'remark',
    type: 'date',
    search: true
  },
  {
    name: '原金额',
    code: 'originalAmount',
    search: false
  },
  {
    name: '金额变动',
    code: 'changeAmount',
    search: false
  },
  {
    name: '当前余额',
    code: 'balance',
    search: false
  },
  {
    name: '操作人',
    code: 'creatorName ',
    search: false
  },
  {
    name: '操作时间',
    code: 'createTime',
    search: false,
    date:true
  },
]);
const dataList = ref<PurchaseAdvice[]>([]);
const ids = ref<Array<string | number>>([]);
const total = ref(0);

const initRow = {
  cover: null,
  sku: null,
  spec: null,
  name: null,
  productId: null,
  advice: null,
  occupy: null,
  stock: null,
  inTransit: null,
  noAuditInTransit: null,
}

const selectedRow = ref<PurchaseAdvice>({...initRow})

const isShowDialog = ref(false)


const queryParams = ref({
  ...initQueryParams
})

const handleSearchQuery = (val) => {
  /***
   * 搜索框查询条件，目前考虑在查询时 queryParams = {...val,pageNo:1,pageSize:10}
   * */
  queryParams.value = {
    ...initQueryParams,
    ...val
  }
  queryList();
}

const handleBtnClick = e => {
  let type = e.type;
  try {
    fn[type](e)
  } catch (e) {
    console.log(`${type}不存在`)
  }
}

const fn = {
  pagination(){
    queryList()
  }
}

const queryList = async () => {
  console.log(queryParams.value)
  let res = await FeeApi.getInOutList({
    ...queryParams.value,
    createTime:queryParams.value.createTime.map(item=>item+' 00:00:00')
  });
  dataList.value = res.list;
  total.value = res.total;
}

const getArea = async () => {

}

onMounted(() => {
  queryList();

  getArea();
})


</script>
<style lang="scss" scoped>

</style>
